Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

144
Views
Axios getPosts error: Unexpected token, expected "," (25:4)

I am trying to get an axios getPosts to work. I am getting a syntax error but I can't find what's wrong with my code.

getPosts = async () => {
    let data = await api.get('/').then(({ data })
    => data);
    this.setState({ posts: data })
  }

The error is posted below:

./src/App.js
SyntaxError: /home/roxx/Documents/eternal_kings_web_app/Twitter-Clone/src/App.js: Unexpected token, expected "," (25:4)

  23 |   getPosts = async () => {
  24 |     let data = await api.get('/').then(({ data })
> 25 |     => data);
     |     ^
  26 |     this.setState({ posts: data })
  27 |   }

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

The source of your syntax error is the newline in your arrow function.

Per MDN on Arrow Functions: "Multiline statements require body braces and return." To stick with the one-line:

let data = await api.get("/").then(({ data }) => data);

And to include the desired setState:

let data = await api.get("/").then(({ data }) => this.setState({ posts: data }));
about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!